package com.kun.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqFanoutConfig {

    //1. 声明交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("order_exchange");
    }


    //2. 声明队列
    @Bean
    public Queue emailQueue(){
        return new Queue("email_queue");
    }

    @Bean
    public Queue smsQueue(){
        return new Queue("sms_queue");
    }


    //3. 绑定队列到交换机
    @Bean
    public Binding bindingEmailQueue(){
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }

    @Bean
    public Binding bindingEmsQueue(){
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }


}
